package com.xiaowen.tool.minio;

import com.xiaowen.tool.SpringContextUtils;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @author admin
 */
@Configuration
public class MinioClientConfig {

    @Value("${minio.endpoint: }")
    private String endpoint;
    @Value("${minio.accessKey: }")
    private String accessKey;
    @Value("${minio.secretKey: }")
    private String secretKey;
    @Value("${minio.bucketName: }")
    private String bucketName;

    /**
     * 注入minio 客户端
     *
     * @return
     */
    public static MinioClient minioClient = null;

    public static MinioClient getMinioClient() {
        if(null == minioClient){
            MinioClientConfig minioClientConfig = SpringContextUtils.getBean("minioClientConfig",MinioClientConfig.class);
            minioClient = MinioClient.builder()
                    .endpoint(minioClientConfig.getEndpoint())
                    .credentials(minioClientConfig.getAccessKey(), minioClientConfig.getSecretKey())
                    .build();
        }
        return minioClient;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }
}
